var app = getApp()

Page({
  data: {
    isAgree: '1'
  },
  onLoad: function (options) {
    var payinfo = JSON.parse(options.payinfo)
    this.setData({
      payinfo: payinfo
    })
  },
  setIsDefault: function () {
    var isAgree = this.data.isAgree
    if (isAgree === '1') {
      isAgree = '0'
    }
    else {
      isAgree = '1'
    }
    this.setData({isAgree: isAgree})
  },
  payVip: function () {
    if (this.data.isAgree !== '1') {
      return
    }
    var payinfo = this.data.payinfo
    var packagestr = "prepay_id=" + payinfo.prepay_id
    app.showLoading()
    wx.requestPayment({
      appId: 'wx93176ec2a9cee7e1',
      timeStamp: payinfo.timeStamp,
      nonceStr: payinfo.nonceStr,
      package: packagestr,
      signType: 'MD5',
      paySign: payinfo.paySign,
      success: res => {
        app.getVipInfo(true)
        app.hideLoading()
        app.toast.success('支付成功')
        setTimeout(() => {
          wx.navigateBack()
        }, 1500)
      },
      fail: res => {
        app.hideLoading()
      }
    })
  },
  showContact: function () {
    wx.navigateTo({
      url: '../../stores/stores?target=contact'
    })
  }
})
